/**
 * author: zhangwei
 * 角色管理列表
 */
var main = {

    init: function() {
        this.initTable();
        this.tabBind();
    },
    initTable: function() {
        var _this=this;
        loadTable();
        // 添加
        $('#btnAdd').click(function() {
            localStorage.doctorCommentType = "add";
            parent.$t.goToPage(this, "/doctorComment/manage");
        });
    },
    tabBind: function() {
        layui.use(['form'], function () {
            var form = layui.form;


        });
    }
}
main.init();

function loadTable() {
    layui.use('table', function(){
        var table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#test'
            ,url:"/doctorComment/queryDoctorCommentPage"
            ,title: '患者评价数据表'
            ,cols: [[
                {type:'numbers', title:'序号', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'doctorCode', title:'医生编码'}
                ,{field:'doctorName', title:'医生名称'}
                ,{field:'appointmentId', title:'预约ID'}
                ,{field:'content', width:500, title:'评价内容'}
                ,{field:'contentType', title:'评价类型', templet: function (res) {
                        if (res.contentType == 1){
                            return '好评'
                        } else if(res.contentType == 2){
                            return '中评'
                        }else if(res.contentType == 3){
                            return '差评'
                        }
                    }}
                ,{field:'score', title:'评分'}
                ,{field:'createTime', width:100, title:'评价时间', templet: function (res) {
                        return formatDate(res.createTime);
                    }}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
            ]]
            ,page: true
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del') {
                layer.confirm('您确定要删除么', function(index){
                    var json = {"id":data.id};
                    $.ajax({
                        type:"get",
                        data:json,
                        async:false,
                        url:"/doctorComment/deleteDoctorComment",
                        success:function(result) {
                            if (result.code == property.successCode) {
                                successMsg("删除成功");
                                loadTable();
                            } else{
                                errorMsg(result.msg);
                            }
                        },
                        error:function(result) {
                            errorMsg("系统异常");
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit'){
                localStorage.doctorCommentType = "edit";
                localStorage.doctorCommentId = data.id;
                parent.$t.goToPage(this, "/doctorComment/manage");
            }
        });
    });
}

